import subprocess

java_code = """
public class HashCodeCalculator {
    public static void main(String[] args) {
            System.out.println(Math.abs("uid_594117890367594497".hashCode()) % 8);
    }
}
"""

# 将 Java 代码保存到一个临时文件，文件名与类名一致
with open('HashCodeCalculator.java', 'w') as f:
    f.write(java_code)

# 编译并运行 Java 代码
result = subprocess.run(['javac', 'HashCodeCalculator.java'], capture_output=True)
if result.returncode == 0:
    result = subprocess.run(['java', 'HashCodeCalculator'], capture_output=True)
    output = result.stdout.decode('utf-8').strip()
    print(output)
else:
    print("编译错误:", result.stderr.decode('utf-8'))
